using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestCecile
{
    public partial class AankoopBrowser : Form
    {

        private string filterSoort = "KLNM";
        public AankoopBrowser()
        {
            InitializeComponent();
        }

        private void AankoopBrowser_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.AANKOOP_KLANT' table. You can move, or remove it, as needed.
            this.aANKOOP_KLANTTableAdapter.Fill(this.dataSet1.AANKOOP_KLANT);
            aANKOOP_KLANTBindingSource.Sort = "AANKDATUM DESC";
        }

        private void txtFilterKlnm_TextChanged(object sender, EventArgs e)
        {
            filterSoort = "KLNM";
        }

        private void dtpFilterVanDatum_ValueChanged(object sender, EventArgs e)
        {
            filterSoort = "DATUM";
        }

        private void dtpFilterTotDatum_ValueChanged(object sender, EventArgs e)
        {
            filterSoort = "DATUM";
        }

        private void txtFilterBedrag_TextChanged(object sender, EventArgs e)
        {
            filterSoort = "BEDRAG";
        }

        private void btnFilter_Click(object sender, EventArgs e)
        {
            string vZoek = txtFilterKlnm.Text.Trim();
            if (filterSoort.Equals("DATUM")) ;
            if (filterSoort.Equals("BEDRAG"))
                vZoek = txtFilterBedrag.Text;
            
            if (vZoek.Length > 0)
            {
                if (vZoek.Substring(0, 1).Equals("'"))
                    vZoek = "'" + vZoek;
            }
            if (filterSoort.Equals("KLNM"))
            {
                aANKOOP_KLANTBindingSource.Filter = "KLNM like '" + vZoek + "%'";
                aANKOOP_KLANTBindingSource.Sort = "KLNM";
            }
            if (filterSoort.Equals("DATUM"))
            {
                aANKOOP_KLANTBindingSource.Filter = "AANKDATUM >= " + "'" + dtpFilterVanDatum.Value.ToShortDateString().ToString() + "'" + " AND " +
                                                    "AANKDATUM <= " + "'" + dtpFilterTotDatum.Value.ToShortDateString().ToString() + "'";
                aANKOOP_KLANTBindingSource.Sort = "AANKDATUM DESC";
            }
            if (filterSoort.Equals("BEDRAG"))
            {
                aANKOOP_KLANTBindingSource.Filter = "BEDRAG > " + vZoek + " AND AANKDATUM > '01/01/2003'";
                aANKOOP_KLANTBindingSource.Sort = "BEDRAG DESC";
            }
            txtFilterBedrag.Text = "";
            txtFilterKlnm.Text = "";
            //Text = filterSoort+" "+this.aANKOOP_KLANTBindingSource.Filter.ToString();
        }

        private void btnAlleAankopen_Click(object sender, EventArgs e)
        {
            aANKOOP_KLANTBindingSource.RemoveFilter();
            aANKOOP_KLANTBindingSource.Sort = "AANKDATUM DESC";
        }

        
    }
}